package com.dxy.df.modules.controller;

import java.util.List;

import com.dxy.df.core.assit.SearchHandler;
import com.dxy.df.core.model.PageRs;
import com.dxy.df.core.model.Rs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.dxy.df.modules.bean.entity.DfCommentEntity;
import com.dxy.df.modules.bean.vo.DfCommentVo;
import com.dxy.df.modules.bean.query.DfCommentQuery;
import com.dxy.df.modules.bean.put.DfCommentPut;
import com.dxy.df.modules.service.DfCommentService;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.validation.Valid;
/**
 * 评论表
 * @author biz@dxy.cn
 * @date 2019-10-25 16:23:46
 */
@Api(tags="评论表")
@RestController
@RequestMapping("/api/comment")
public class DfCommentController {

	@Autowired
	private DfCommentService dfCommentService;
	@Autowired
	private SearchHandler searchHandler;

    @ApiOperation(value = "评论表分页列表")
	@PostMapping("/search")
	public PageRs<DfCommentVo> search(@RequestBody @Valid DfCommentQuery query){
		//查询列表数据
        List<DfCommentVo> voList =  dfCommentService.queryList(query);
        int total = dfCommentService.queryTotal(query);
		return searchHandler.search(voList,total,query);
	}
	

    @ApiOperation(value = "评论表信息")
	@GetMapping("/info/{id}")
	public Rs<DfCommentEntity> info(@PathVariable("id") Integer id){
		DfCommentQuery query = new DfCommentQuery();
        query.setId(id);
		DfCommentEntity dfComment = dfCommentService.queryObject(query);

        return Rs.ok().putData(dfComment);
	}

    @ApiOperation(value = "评论表新增")
	@PostMapping
	public Rs save(@RequestBody DfCommentPut dfComment){
		dfCommentService.save(dfComment);
		return Rs.ok();
	}

    @ApiOperation(value = "评论表修改")
	@PutMapping
	public Rs update(@RequestBody DfCommentPut dfComment){
		dfCommentService.update(dfComment);
		return Rs.ok();
	}

    @ApiOperation(value = "评论表删除")
	@DeleteMapping
	public Rs delete(@RequestParam Integer[] ids){
		dfCommentService.deleteBatch(ids);
		return Rs.ok();
	}
	
}
